﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using DAL;
using BUS;
using Utility;
using System.Security.Cryptography;
using System.Text;
using System.Web.Security;

public partial class Admin_NhanVien_Them : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadComboBox();
        }
    }

    private int Kiemtra(string s)
    {
        try
        {
            NhanVien nhanvien = NhanVienBUS.GetById(s);
            if (nhanvien.TenDangNhap_NhanVien != "")
            {
                return 1;
            }
            else return 0;
        }
        catch
        { return 0; }
    }
    protected void btn_Insert_Click(object sender, EventArgs e)
    {
        if (txt_TenNhanVien.Text != "" && txt_TenDangNhap.Text != "" && txt_Password_NhanVien.Text != "" && Kiemtra(txt_TenDangNhap.Text) == 0)
        {

            NhanVien nv = new NhanVien();
            nv.TenDangNhap_NhanVien = txt_TenDangNhap.Text;
            string Pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txt_Password_NhanVien.Text, "SHA1");
            nv.MatKhau_NhanVien = Pass;
            nv.TenNhanVien = txt_TenNhanVien.Text;
            nv.DiaChi = txt_DiaChi.Text;
            nv.DienThoai = txt_DienThoai.Text;
            nv.Email = txt_Email.Text;
            nv.MaPhanQuyen = DropDownList_PhanQuyen.SelectedIndex;
            nv.TrangThai = 1;

            NhanVienBUS.INSERT(nv);
            Response.Redirect("NhanVien.aspx");
        }
    }

    protected void LoadComboBox()
    {
        DropDownList_PhanQuyen.Items.Insert(0,"Quản lý");
        DropDownList_PhanQuyen.Items.Insert(1,"Nhân viên");
    }
}